﻿using System.Collections.Generic;
using System.Linq;
using Wicresoft.SelfService.BL.Interface;
using System.Configuration;
using Wicresoft.SelfService.DAL;
using Wicresoft.SelfService.DAO;
using Oracle.DataAccess.Client;

namespace Wicresoft.SelfService.BL
{
    public class MyAppSystem : IAppSystem
    {
        public List<BusinessSystem> getAppSystem(string company)
        {
            ITServiceDAL itService = new ITServiceDAL();
            List<BusinessSystem> appSystems = itService.getBusinessSystem_By_QueryParams(null, null, null, null);
            itService.Dispose();
            List<BusinessSystem> appSystemsResult = new List<BusinessSystem>();
            foreach (BusinessSystem bs in appSystems)
            {
                if (string.Compare(bs.Company, company, true) == 0 || bs.isUnified == 1)
                {
                    appSystemsResult.Add(bs);
                }
            }
            return appSystemsResult;
        }
        public BusinessSystem getAppSystem_By_AppName(string appName, string company)
        {
            ITServiceDAL itService = new ITServiceDAL();
            QueryParameters[] attParam = new QueryParameters[] {
                    new QueryParameters(){ OracleDbName="NAME", OracleDbType=OracleDbType.NVarchar2, OracleDbSize=50, OracleDbValue=appName.ToLower(), PredicateType=PredicateType.where, QueryOperator=QueryOperatorType.equal}
                    };
            List<BusinessSystem> appSystems = itService.getBusinessSystem_By_QueryParams(attParam, null, null, null);
            itService.Dispose();
            BusinessSystem bs = null;
            foreach (BusinessSystem b in appSystems)
            {
                if (string.Compare(b.Company, company, true) == 0 || b.isUnified == 1)
                {
                    bs = b;
                    break;
                }
            }
            return bs;
        }
        public BusinessSystem getAppSystem_By_ID(int id)
        {
            ITServiceDAL itService = new ITServiceDAL();
            QueryParameters[] attParam = new QueryParameters[] {
                    new QueryParameters(){ OracleDbName="ID", OracleDbType=OracleDbType.Int32, OracleDbValue=id, PredicateType=PredicateType.where, QueryOperator=QueryOperatorType.equal}
                    };
            List<BusinessSystem> appSystems = itService.getBusinessSystem_By_QueryParams(attParam, null, null, null);
            itService.Dispose();

            return appSystems.FirstOrDefault();
        }
        public List<BusinessSystem> getAppSystem_By_AppCategory(string category, string company)
        {
            ITServiceDAL itService = new ITServiceDAL();
            QueryParameters[] attParam = new QueryParameters[] {
                    new QueryParameters(){ OracleDbName="CATEGORY", OracleDbType=OracleDbType.NVarchar2, OracleDbSize=50, OracleDbValue=category.ToLower(), PredicateType=PredicateType.where, QueryOperator=QueryOperatorType.equal}
                    };
            List<BusinessSystem> appSystems = itService.getBusinessSystem_By_QueryParams(attParam, null, null, null);
            itService.Dispose();
            List<BusinessSystem> appSystemsResult = new List<BusinessSystem>();
            foreach (BusinessSystem bs in appSystems)
            {
                if (string.Compare(bs.Company, company, true) == 0 || bs.isUnified == 1)
                {
                    appSystemsResult.Add(bs);
                }
            }
            return appSystemsResult;
        }
    }
}
